<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /* for (let i = 1; i <= 9; i++) { 
            let ride = '';
            for (let j = 1; j <= i; j++) {
                ride = ride + `${i} * ${j} = ${i*j}   `;
            }
            console.log(ride);
        } */
        // let i = 1;
        // let sum = 0;
        /*   while (i <= 100) {
              sum = sum + i;
              i++
          }
          console.log(sum); */

        /*  do {
             sum = sum + i;
             i++
         } while (i<=100);
         console.log(sum) */

        /* [2, 6, 6, 1, 77, 52, 25, 7 ,7]
        1. 数组的最大值
        2. 数组的求和，平均数
        3. 筛选数组中大于 10 的元素放入新的数组
        4. 删除数组中的奇数
        5. 翻转元素，放入新的数组
        6. 数组的去重,形成新的数组
        7. 数组转换为字符串
        8. 数组的排序 */

        // 1. 数组的最大值

        /* let max=arr[0];
        for(let impt of arr){
            if(impt>max){
                max=impt;
            }
        }
        console.log(max); */
        // 2. 数组的求和，平均数

        /* let sum = 0;
         for(let index in arr){
            sum = sum+arr[index];
         }
         console.log(sum);
         console.log(sum/arr.length); */
        // 3. 筛选数组中大于 10 的元素放入新的数组

        /*  let arr1 = [];
             for(let i = 0;i <arr.length;i++){
                 if(arr[i]>10){
                     arr1[arr1.length]=arr[i];
                 }
                 
             }
             console.log(arr1); */
        // 4. 删除数组中的奇数

        /* let arr1 = [];
        for (let i = 0; i < arr.length; i++) {
            if (arr[i] % 2 == 0) {
                arr1[arr1.length] = arr[i];
            }

        }
        console.log(arr1); */
        // 5. 翻转元素，放入新的数组

        /*  let arr1 = [];
             for(let i= arr.length-1;i>=0;i--){
                 arr1[arr1.length]=arr[i];
             }
             console.log(arr1); */
        // 6. 数组的去重,形成新的数组
        let arr = [2, 6, 6, 1, 77, 52, 25, 7, 7];
        /* let arr1 = [];
        for(let i = 0; i < arr.length; i++) {
            let isCommit = false;
            for (let j = 0; j < arr.length; j++) {
                if (arr[i] == arr1[j]) {
                    isCommit = true;
                }
            }
            if(!isCommit){
                arr1[arr1.length]=arr[i];
            }
        }
        console.log(arr1); */
        // 7. 数组转换为字符串

        /*   let str=`[`;
          for(let i = 0; i < arr.length; i++) {
                  if (i != arr.length-1) {
                      str=str+`'${arr[i]}', `;
                  }else{
                      str=str+`'${arr[i]}'`;
                  }
          }
           str=str+`]`;
          console.log(str); */
        // 8. 数组的排序

        for (let i = 1; i < arr.length; i++) {
            for (let j = 0; j <= arr.length-i; j++) {
                if (arr[j] > arr[j + 1]) {
                    let timp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = timp;
                }
                
            }

        }
        console.log(arr); 
    </script>
</body>

</html>